grammar Grin; 

options {
  backtrack=true;
}

//---------------------------------------
// CORE RULES
//---------------------------------------


grin: (comment | directive | style_definition)*;

comment: '#' phrase;

style: STYLE_TYPE ':' phrase;
inline_style_use: '{' (style ';')* style ';'? '}' ;
style_name: '@' WORD;
style_definition: style_name inline_style_use;
style_use: inline_style_use | style_name;

directive: style_use? (text|image|label|play);
text: phrase | 'text' multi_line_phrase 'endtext';
image: 'image' WORD phrase;
label: 'label' phrase | 'label' multi_line_phrase  'endlabel';
play: 'play' (directive NEWLINE)* 'stop';

phrase : WORD*;
multi_line_phrase : (phrase NEWLINE)*;

//---------------------------------------
// TERMINALS
//---------------------------------------


STYLE_TYPE : ('duration'|'bgcolor'|'color'|'position');
WORD : ('a'..'z'|'A'..'Z'|'0'..'9'|'-'|'.'|'/'|'\\')+;
NEWLINE	 : ('\r\n'|'\n' );
WS : (' '|'\t'|'\r'|'\n' )+ {$channel=HIDDEN;};
